/// 用户信息数据模型
class UserModel {
  /// 用户ID
  String? userId;
  
  /// 用户名
  String? username;
  
  /// 密码
  String? password;
  
  /// 手机号
  String? phone;
  
  /// 头像
  String? avatar;
  
  /// 姓名
  String? realName;
  
  /// 性别 1:男 2:女
  int? gender;
  
  /// 是否同意用户协议
  bool? agreement;
  
  /// 诊所审核状态 1:通过 0:未通过
  int? clinicAuditStatus;
  
  /// 用户审核状态 1:通过 0:未通过
  int? userAuditStatus;
  
  /// 账号启用状态 1:启用 0:禁用
  int? enableStatus;
  
  /// 构造函数
  UserModel({
    this.userId,
    this.username,
    this.password,
    this.phone,
    this.avatar,
    this.realName,
    this.gender,
    this.agreement,
    this.clinicAuditStatus,
    this.userAuditStatus,
    this.enableStatus,
  });
  
  /// 从JSON创建对象
  factory UserModel.fromJson(Map<String, dynamic> json) {
    return UserModel(
      userId: json['user_id']?.toString(),
      username: json['username']?.toString(),
      password: json['password']?.toString(),
      phone: json['phone']?.toString(),
      avatar: json['avatar']?.toString(),
      realName: json['real_name']?.toString(),
      gender: json['gender'] is int ? json['gender'] : int.tryParse(json['gender']?.toString() ?? ''),
      agreement: json['agreement'] == true || json['agreement'] == 1,
      clinicAuditStatus: json['clinic_audit_status'] is int ? json['clinic_audit_status'] : int.tryParse(json['clinic_audit_status']?.toString() ?? ''),
      userAuditStatus: json['user_audit_status'] is int ? json['user_audit_status'] : int.tryParse(json['user_audit_status']?.toString() ?? ''),
      enableStatus: json['enable_status'] is int ? json['enable_status'] : int.tryParse(json['enable_status']?.toString() ?? ''),
    );
  }
  
  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'user_id': userId,
      'username': username,
      'password': password,
      'phone': phone,
      'avatar': avatar,
      'real_name': realName,
      'gender': gender,
      'agreement': agreement,
      'clinic_audit_status': clinicAuditStatus,
      'user_audit_status': userAuditStatus,
      'enable_status': enableStatus,
    };
  }
  
  /// 复制对象
  UserModel copyWith({
    String? userId,
    String? username,
    String? password,
    String? phone,
    String? avatar,
    String? realName,
    int? gender,
    bool? agreement,
    int? clinicAuditStatus,
    int? userAuditStatus,
    int? enableStatus,
  }) {
    return UserModel(
      userId: userId ?? this.userId,
      username: username ?? this.username,
      password: password ?? this.password,
      phone: phone ?? this.phone,
      avatar: avatar ?? this.avatar,
      realName: realName ?? this.realName,
      gender: gender ?? this.gender,
      agreement: agreement ?? this.agreement,
      clinicAuditStatus: clinicAuditStatus ?? this.clinicAuditStatus,
      userAuditStatus: userAuditStatus ?? this.userAuditStatus,
      enableStatus: enableStatus ?? this.enableStatus,
    );
  }
}